//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.example.demo1101.demo4;


import com.example.demo3.Ticket;

import java.util.Arrays;

public class TestTicket02_AutoLock {
    private static String[] arr = new String[2];
    private static int index = 0;
    private static Object lock = new Object();

    public TestTicket02_AutoLock() {
    }

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new Ticket() {
            public void run() {
                synchronized(TestTicket02_AutoLock.lock) {
                    if (TestTicket02_AutoLock.arr[TestTicket02_AutoLock.index] == null) {
                        TestTicket02_AutoLock.arr[TestTicket02_AutoLock.index] = "野猪佩奇";
                        TestTicket02_AutoLock.index++;
                    }

                }
            }
        });
        Thread t2 = new Thread(new Ticket() {
            public void run() {
                synchronized(TestTicket02_AutoLock.lock) {
                    if (TestTicket02_AutoLock.arr[TestTicket02_AutoLock.index] == null) {
                        TestTicket02_AutoLock.arr[TestTicket02_AutoLock.index] = "野猪乔治";
                        TestTicket02_AutoLock.index++;
                    }

                }
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(Arrays.toString(arr));
    }
}
